<!DOCTYPE html>
<html lang=en>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5" />
    <meta name="description" content="一对多我们每个人和自己的书就是一对多的关系，当然在这里我们认为书是私有的，属于个人财产。  于是我们建立person表和book表 123456DROP TABLE IF EXISTS &#96;person&#96;;CREATE TABLE &#96;person&#96; (    &#96;id&#96;            INT         NOT NULL        AUTO_INCREMENT,    &#96;person_">
<meta property="og:type" content="article">
<meta property="og:title" content="一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询">
<meta property="og:url" content="https://cheung0-bit.github.io/132732cb74cf/index.html">
<meta property="og:site_name" content="Bruce Zhang&#39;s Blogs">
<meta property="og:description" content="一对多我们每个人和自己的书就是一对多的关系，当然在这里我们认为书是私有的，属于个人财产。  于是我们建立person表和book表 123456DROP TABLE IF EXISTS &#96;person&#96;;CREATE TABLE &#96;person&#96; (    &#96;id&#96;            INT         NOT NULL        AUTO_INCREMENT,    &#96;person_">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/0c08b34b41aefa8d37ecdad2528e0a54.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/0dc385bcd00db66f2e8768aa4a8678db.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/0163135a94080c9f969c634a57abdcba.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/2cc14e21c2f96afafce9135e53da12c0.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/23c554a6ee91937dc895b914ebcff388.png">
<meta property="article:published_time" content="2021-11-05T13:09:12.000Z">
<meta property="article:modified_time" content="2022-11-25T06:53:14.095Z">
<meta property="article:author" content="张林">
<meta property="article:tag" content="MySQL">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/0c08b34b41aefa8d37ecdad2528e0a54.png">
    
    
      
        
          <link rel="shortcut icon" href="/images/favicon.ico">
        
      
      
        
          <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
        
      
      
        
          <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
        
      
    
    <!-- title -->
    <title>一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
    <!-- rss -->
    
    
      <link rel="alternate" href="/atom.xml" title="Bruce Zhang&#39;s Blogs" type="application/atom+xml" />
    
	<!-- mathjax -->
	
<meta name="generator" content="Hexo 7.0.0"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" aria-label="Top" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
        <!--
       --><li><a href="/">Home</a></li><!--
     --><!--
       --><li><a href="/about/">About</a></li><!--
     --><!--
       --><li><a href="/archives/">Articles</a></li><!--
     --><!--
       --><li><a href="/categories/">Category</a></li><!--
     --><!--
       --><li><a href="/search/">Search</a></li><!--
     -->
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" aria-label="Previous post" href="/dfe61ddc5a2b/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" aria-label="Next post" href="/b45bf59cab8f/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" aria-label="Back to top" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" aria-label="Share post" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">Previous post</span>
      <span id="i-next" class="info" style="display:none;">Next post</span>
      <span id="i-top" class="info" style="display:none;">Back to top</span>
      <span id="i-share" class="info" style="display:none;">Share post</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://cheung0-bit.github.io/132732cb74cf/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://cheung0-bit.github.io/132732cb74cf/&text=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://cheung0-bit.github.io/132732cb74cf/&is_video=false&description=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询&body=Check out this article: https://cheung0-bit.github.io/132732cb74cf/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://cheung0-bit.github.io/132732cb74cf/&name=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://cheung0-bit.github.io/132732cb74cf/&t=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E5%AF%B9%E5%A4%9A"><span class="toc-number">1.</span> <span class="toc-text">一对多</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%9A%E5%AF%B9%E5%A4%9A"><span class="toc-number">2.</span> <span class="toc-text">多对多</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">张林</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2021-11-05T13:09:12.000Z" itemprop="datePublished">2021-11-05</time>
        
        (Updated: <time datetime="2022-11-25T06:53:14.095Z" itemprop="dateModified">2022-11-25</time>)
        
      
    </div>


      
    <div class="article-category">
        <i class="fas fa-archive"></i>
        <a class="category-link" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a>
    </div>


      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link-link" href="/tags/MySQL/" rel="tag">MySQL</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h3 id="一对多"><a href="#一对多" class="headerlink" title="一对多"></a>一对多</h3><p>我们每个人和自己的书就是一对多的关系，当然在这里我们认为书是私有的，属于个人财产。</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/0c08b34b41aefa8d37ecdad2528e0a54.png" alt="image-20211105150814963"></p>
<p>于是我们建立<code>person</code>表和<code>book</code>表</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> `person`;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> `person` (</span><br><span class="line">    `id`            <span class="type">INT</span>         <span class="keyword">NOT</span> <span class="keyword">NULL</span>        AUTO_INCREMENT,</span><br><span class="line">    `person_name`   <span class="type">VARCHAR</span>(<span class="number">16</span>) <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span>    <span class="keyword">UNIQUE</span>,</span><br><span class="line">     <span class="keyword">PRIMARY</span> KEY (`id`)</span><br><span class="line">) ENGINE<span class="operator">=</span>INNODB <span class="keyword">DEFAULT</span> CHARSET<span class="operator">=</span>utf8mb4;</span><br></pre></td></tr></table></figure>

<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> `book`;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> `book` (</span><br><span class="line">    `id`        <span class="type">INT</span>         <span class="keyword">NOT</span> <span class="keyword">NULL</span>        AUTO_INCREMENT,</span><br><span class="line">    `book_name` <span class="type">VARCHAR</span>(<span class="number">50</span>) <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span>    <span class="keyword">UNIQUE</span>,</span><br><span class="line">    `person_id` <span class="type">INT</span>         <span class="keyword">NOT</span> <span class="keyword">NULL</span>,</span><br><span class="line">     <span class="keyword">PRIMARY</span> KEY (`id`)</span><br><span class="line">) ENGINE<span class="operator">=</span>INNODB <span class="keyword">DEFAULT</span> CHARSET<span class="operator">=</span>utf8mb4;</span><br></pre></td></tr></table></figure>

<p>插入测试值</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> `person`</span><br><span class="line"><span class="keyword">VALUES</span> (<span class="number">1</span>,<span class="string">&#x27;Tom&#x27;</span>),</span><br><span class="line">       (<span class="number">2</span>,<span class="string">&#x27;Bob&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> `book`</span><br><span class="line"><span class="keyword">VALUES</span>  (<span class="number">1</span>,<span class="string">&#x27;JAVA从入门到入土&#x27;</span>,<span class="number">1</span>),</span><br><span class="line">        (<span class="number">2</span>,<span class="string">&#x27;WEB渗透从入门到入狱&#x27;</span>,<span class="number">1</span>),</span><br><span class="line">        (<span class="number">3</span>,<span class="string">&#x27;数据结构与算法&#x27;</span>,<span class="number">2</span>),</span><br><span class="line">        (<span class="number">4</span>,<span class="string">&#x27;平凡的世界&#x27;</span>,<span class="number">1</span>);</span><br></pre></td></tr></table></figure>

<p>通过在<code>book</code>表中创建的<code>person_id</code>字段，我们很容易通过连接表查询到个人与书籍的对应情况：</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/0dc385bcd00db66f2e8768aa4a8678db.png" alt="image-20211105144733375"></p>
<h3 id="多对多"><a href="#多对多" class="headerlink" title="多对多"></a>多对多</h3><p>学生每天都要上课，而学生与课程之间的关系就是多对多的关系</p>
<p>一个学生要上好几门课，而每门课也会被多个学生上(额…好像有点奇怪)</p>
<p>因此我们需要建立三张表，其中有一张用来联系另外两张表</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/0163135a94080c9f969c634a57abdcba.png" alt="image-20211105151515355"></p>
<p>建表</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> `student`;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> `student` (</span><br><span class="line">    `id`            <span class="type">INT</span>         <span class="keyword">NOT</span> <span class="keyword">NULL</span>        AUTO_INCREMENT,</span><br><span class="line">    `student_name`  <span class="type">VARCHAR</span>(<span class="number">12</span>) <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span>    <span class="keyword">UNIQUE</span>,</span><br><span class="line">     <span class="keyword">PRIMARY</span> KEY (`id`)</span><br><span class="line">) ENGINE<span class="operator">=</span>INNODB <span class="keyword">DEFAULT</span> CHARSET<span class="operator">=</span>utf8mb4;</span><br><span class="line"></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> `course`;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> `course` (</span><br><span class="line">    `id`            <span class="type">INT</span>         <span class="keyword">NOT</span> <span class="keyword">NULL</span>        AUTO_INCREMENT,</span><br><span class="line">    `course_name`   <span class="type">VARCHAR</span>(<span class="number">30</span>) <span class="keyword">DEFAULT</span> <span class="keyword">NULL</span>    <span class="keyword">UNIQUE</span>,</span><br><span class="line">     <span class="keyword">PRIMARY</span> KEY (`id`)</span><br><span class="line">) ENGINE<span class="operator">=</span>INNODB <span class="keyword">DEFAULT</span> CHARSET<span class="operator">=</span>utf8mb4;</span><br><span class="line"></span><br><span class="line"><span class="keyword">DROP</span> <span class="keyword">TABLE</span> IF <span class="keyword">EXISTS</span> `student_course`;</span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> `student_course` (</span><br><span class="line">    `student_id`  <span class="type">INT</span>   <span class="keyword">NOT</span> <span class="keyword">NULL</span>,</span><br><span class="line">    `course_id`   <span class="type">INT</span>   <span class="keyword">NOT</span> <span class="keyword">NULL</span>,</span><br><span class="line">     <span class="keyword">PRIMARY</span> KEY (`student_id`,`course_id`),</span><br><span class="line">     <span class="keyword">FOREIGN</span> KEY (`student_id`) <span class="keyword">REFERENCES</span> `student` (`id`) <span class="keyword">ON</span> <span class="keyword">DELETE</span> CASCADE <span class="keyword">ON</span> <span class="keyword">UPDATE</span> CASCADE,</span><br><span class="line">     <span class="keyword">FOREIGN</span> KEY (`course_id`)  <span class="keyword">REFERENCES</span> `course`  (`id`) <span class="keyword">ON</span> <span class="keyword">DELETE</span> CASCADE <span class="keyword">ON</span> <span class="keyword">UPDATE</span> CASCADE</span><br><span class="line">) ENGINE<span class="operator">=</span>INNODB <span class="keyword">DEFAULT</span> CHARSET<span class="operator">=</span>utf8mb4;</span><br></pre></td></tr></table></figure>

<p>插入数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> `student`</span><br><span class="line"><span class="keyword">VALUES</span> (<span class="number">1</span>,<span class="string">&#x27;Tom&#x27;</span>),</span><br><span class="line">       (<span class="number">2</span>,<span class="string">&#x27;Bob&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> `course`</span><br><span class="line"><span class="keyword">VALUES</span>  (<span class="number">1</span>,<span class="string">&#x27;JAVA程序设计&#x27;</span>),</span><br><span class="line">        (<span class="number">2</span>,<span class="string">&#x27;大学物理&#x27;</span>),</span><br><span class="line">        (<span class="number">3</span>,<span class="string">&#x27;数据结构与算法&#x27;</span>),</span><br><span class="line">        (<span class="number">4</span>,<span class="string">&#x27;C++面向对象程序设计&#x27;</span>);</span><br><span class="line">   </span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> `student_course`</span><br><span class="line"><span class="keyword">VALUES</span>  (<span class="number">1</span>,<span class="number">1</span>),</span><br><span class="line">        (<span class="number">1</span>,<span class="number">3</span>),</span><br><span class="line">        (<span class="number">1</span>,<span class="number">4</span>),</span><br><span class="line">        (<span class="number">2</span>,<span class="number">2</span>),</span><br><span class="line">        (<span class="number">2</span>,<span class="number">4</span>);</span><br></pre></td></tr></table></figure>

<p>连接查询每个学生要上哪些课以及每门课被哪些学生上:thinking:</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/2cc14e21c2f96afafce9135e53da12c0.png" alt="image-20211105155428928"></p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/23c554a6ee91937dc895b914ebcff388.png" alt="image-20211105160607332"></p>
<p><strong>OK,完结撒花</strong></p>

  </div>
</article>


    <div class="blog-post-comments">
        <div id="utterances_thread">
            <noscript>Please enable JavaScript to view the comments.</noscript>
        </div>
    </div>


        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Articles</a></li>
         
          <li><a href="/categories/">Category</a></li>
         
          <li><a href="/search/">Search</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E5%AF%B9%E5%A4%9A"><span class="toc-number">1.</span> <span class="toc-text">一对多</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%9A%E5%AF%B9%E5%A4%9A"><span class="toc-number">2.</span> <span class="toc-text">多对多</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://cheung0-bit.github.io/132732cb74cf/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://cheung0-bit.github.io/132732cb74cf/&text=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://cheung0-bit.github.io/132732cb74cf/&is_video=false&description=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询&body=Check out this article: https://cheung0-bit.github.io/132732cb74cf/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://cheung0-bit.github.io/132732cb74cf/&title=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://cheung0-bit.github.io/132732cb74cf/&name=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://cheung0-bit.github.io/132732cb74cf/&t=一个简单的示例，让你学会 MySQL一对多和多对多的建表与查询"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> Menu</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> TOC</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> Share</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> Top</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
      
        
          2022-2024
            <a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/">
              苏ICP备2022044873号
            </a>
  </div>
  <div class="footer-right">
    <nav>
      <ul>
        
          <!--
       -->
          <li><a href="/">
              Home
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/about/">
              About
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/archives/">
              Articles
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/categories/">
              Category
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/search/">
              Search
            </a></li>
          <!--
     -->
          
      </ul>
    </nav>
  </div>
</footer>
    </div>
    <!-- styles -->


 
  <link
    rel="preload"
    href="/lib/font-awesome/css/all.min.css"
    as="style"
    onload="this.onload=null;this.rel='stylesheet'"
  />
  <noscript
    ><link
      rel="stylesheet"
      href="/lib/font-awesome/css/all.min.css"
  /></noscript>



    <!-- jquery -->
 
  
<script src="/lib/jquery/jquery.min.js"></script>





<!-- clipboard -->

   
    
<script src="/lib/clipboard/clipboard.min.js"></script>

  
  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"Copy to clipboard!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "Copied!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

  <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?4484a4a33014b59670c470a6e15a66db";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
        </script>

<!-- Cloudflare Analytics -->

<!-- Umami Analytics -->

<!-- Disqus Comments -->

<!-- utterances Comments -->

    <script type="text/javascript">
      var utterances_repo = 'Cheung0-bit/blog-package';
      var utterances_issue_term = 'title';
      var utterances_label = 'Comment';
      var utterances_theme = 'github-dark';

      (function(){
          var script = document.createElement('script');

          script.src = 'https://utteranc.es/client.js';
          script.setAttribute('repo', utterances_repo);
          script.setAttribute('issue-term', 'pathname');
          script.setAttribute('label', utterances_label);
          script.setAttribute('theme', utterances_theme);
          script.setAttribute('crossorigin', 'anonymous');
          script.async = true;
          (document.getElementById('utterances_thread')).appendChild(script);
      }());
  </script>

</body>
</html>
